#include "AutoLock.h"
#include "CritSection.h"
#include "../include/mystdafx.h"

//////////////////////////////////////////////////////////////////////////

#ifdef _LOCK_DEBUG
CAutoLock::CAutoLock(ICritSection& cs, const char* strFilePath, DWORD dwFileLine)
{
	m_pCritSection = &cs;

	assert( strlen( strFilePath ) < OS_MAX_PATH-1 );
	strcpy( m_lockinfo.strFilePath, strFilePath );
	m_lockinfo.dwFileLine = dwFileLine;
	if(m_pCritSection != NULL)
		m_pCritSection->Lock(strFilePath, dwFileLine);
}
#else
CAutoLock::CAutoLock(ICritSection& cs)
{
	m_pCritSection = &cs;

	if(m_pCritSection != NULL)
		m_pCritSection->Lock();
}
#endif

//CAutoLock::CAutoLock( LPCRITICAL_SECTION cs )
//: m_cs(cs)
//{
//	if( NULL != m_cs )
//	{
//		::EnterCriticalSection( m_cs );
//	}
//	else
//	{
//		::EnterCriticalSection( &s_gLock );
//	}
//}

CAutoLock::~CAutoLock()
{
	if( NULL != m_pCritSection )
	{
#ifndef _LOCK_DEBUG
		m_pCritSection->Unlock();
#else
		m_pCritSection->Unlock(m_lockinfo.strFilePath, m_lockinfo.dwFileLine);
#endif
	}
}
